import request from "@/api";
import { BaseRet, PageQuery, PageRet } from "../../response";

class UserApi {
  /**
   * 查询
   * @param data
   * @returns
   */
  static async query(data: UserQuery): Promise<PageRet<UserList>> {
    return await request({
      url: "/sysuser/index",
      method: "post",
      data: data,
    });
  }

  /**
   * 新增
   * @param data
   * @returns
   */
  static async create(data: EditUser): Promise<BaseRet> {
    return await request({
      url: "/sysuser/create",
      method: "post",
      data: data,
    });
  }

  /**
   * 更新
   * @param data
   * @returns
   */
  static async update(data: EditUser): Promise<BaseRet> {
    return await request({
      url: "/sysuser/update",
      method: "put",
      data: data,
    });
  }

  /**
   * 删除
   * @param id
   * @returns
   */
  static async delete(id: string): Promise<BaseRet> {
    return await request({
      url: `/sysuser/delete/${id}`,
      method: "delete",
    });
  }

  /**
   * 重置密码
   * @param id
   * @returns
   */
  static async resetPassword(id: string): Promise<BaseRet> {
    return await request({
      url: `/sysuser/ResetPassword/${id}`,
      method: "get",
    });
  }
}

export default UserApi;

export interface UserList {
  id: string;
  userName?: string;
  nickName?: string;
  email?: string;
  phone?: string;
  isAdmin?: boolean;
  isEnabled?: boolean;
}

export interface EditUser {
  id: string;
  userName?: string;
  nickName?: string;
  email?: string;
  phone?: string;
  isAdmin?: boolean;
  isEnabled?: boolean;
}

export interface UserQuery extends PageQuery {
  searchString: string;
}
